{include file="public/top" /}

<body>
<div class="x-body">
    <form class="layui-form">
        <input type="hidden" name="id" value="1">
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>SMTP服务器
            </label>
            <div class="layui-input-block">
                <input type="text" id="smtp" name="smtp" value="{$data.smtp}" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>

        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>邮件名
            </label>
            <div class="layui-input-block">
                <input type="text" id="name" name="name" value="{$data.name}" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>发件人地址
            </label>
            <div class="layui-input-block">
                <input type="text" id="addresser" name="addresser" value="{$data.addresser}" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>发件人姓名
            </label>
            <div class="layui-input-block">
                <input type="text" id="addressername" name="addressername" value="{$data.addressername}" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>邮箱授权码
            </label>
            <div class="layui-input-block">
                <input type="password" id="password" name="password" value="{$data.password}" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>邮件编码
            </label>
            <div class="layui-input-block">
                <input type="text" id="coding" name="coding" value="{$data.coding}" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>是否smtp认证
            </label>
            <div class="layui-input-block">
                <input type="radio" name="smtp_attestation" value="1" title="是" {if $data.smtp_attestation eq 1}checked{/if}>
                <input type="radio" name="smtp_attestation" value="2" title="否" {if $data.smtp_attestation eq 2}checked{/if}>
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>是否发送html格式
            </label>
            <div class="layui-input-block">
                <input type="radio" name="html" value="1" title="是" {if $data.html eq 1}checked{/if}>
                <input type="radio" name="html" value="2" title="否" {if $data.html eq 2}checked{/if}>
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>订单通知邮箱
            </label>
            <div class="layui-input-block">
                <input type="text" id="order_inform" name="order_inform" value="{$data.order_inform}" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <button type="button"  class="layui-btn layui-btn-normal" lay-filter="add" lay-submit="" style="margin-left: 100px">提交</button>
        </div>
    </form>
</div>
<script>

    var addurl = '/admin/setup/email';
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;

        //自定义验证规则
        form.verify({
            pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,repass: function(value){
                if($('#L_pass').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }
        });
        //监听提交
        form.on('submit(add)', function(data){
            $.post(addurl, data.field,function(res) {
                var success = JSON.parse(res);
                if(success.code===200){
                    layer.msg(success.msg, {
                        time: 1000, //不自动关闭
                        icon:6,
                        end:function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }
                    });
                    return false;
                }else {
                    layer.msg(success.msg)
                }


            });

        });
    });

</script>
</body>

</html>